package com.chunguang.netty.listener;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import com.chunguang.netty.comon.Client;

@Component("springListener")
public class SpringListener implements ApplicationListener<ContextRefreshedEvent>{

	ExecutorService single = Executors.newSingleThreadExecutor();
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
	    if(event.getApplicationContext().getParent() == null){
	        //需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。  
	    	System.out.println("spring 加载完毕..");
			try {
				single.execute(new  Runnable() {
					public void run() {
						Client.getInstance().connect();
					}
				});
			} catch (Exception e) {
				e.printStackTrace();
			}
	    }  		
		


	}



}
